A constant is a fixed name for a value that never changes, and GBML gives you named constants for buttons, text alignment, path endings, tile types, colors and door modes so you never type a bare number.
A variable is a named box whose contents you change while the game runs: hp = hp - 1;. A constant is a name for a value that is decided once and never changes. BTN_A always means the A button. COLOR_RED always means red. You read a constant. You never assign to one.
GBML writes its own constants in capital letters, with a short prefix that says which job they are for. BTN_ is for buttons, COLOR_ is for colors. That makes them easy to spot in code, and easy to tell apart from your own variables.
Suppose the engine numbered its buttons and you had to remember that the A button is 0 and START is 4. You would write btn_held(4) and read it back a week later with no idea what it meant. btn_held(BTN_START) says it on the page.
There is a second reason, and it matters more. A misspelled name is an error. A wrong number is not. Type BTN_STRAT and the compiler stops and tells you. Type 5 where you meant 4 and the game builds and does the wrong thing, with nothing to point at. A named value moves the mistake from "silent" to "caught before you ever run the game".
A third reason: the engine, not you, decides what the underlying value is. If it changes how it represents a button, every constant keeps working, and code that used raw numbers would not.
There are 31, in six families. Each family is used by one group of functions, and the prefix tells you which.
| Family | Constants | Used with |
|---|---|---|
| Buttons | BTN_A, BTN_B, BTN_L, BTN_R, BTN_START, BTN_SELECT, BTN_UP, BTN_DOWN, BTN_LEFT, BTN_RIGHT, and for a Sega Genesis pad BTN_C, BTN_X, BTN_Y, BTN_Z, BTN_MODE | btn_held, btn_pressed, btn_released - the ten buttons a GBA has; the last five exist only on a console whose pad has them, and the check refuses a button the console lacks |
| Text alignment | ALIGN_LEFT, ALIGN_CENTER, ALIGN_RIGHT | text_align - which part of the text sits on the x you draw at |
| Path endings | PATH_STOP, PATH_LOOP, PATH_PING_PONG, PATH_CONTINUE | path_start and path_end_do - what an instance does on reaching the end of a route |
| Tile types | TILE_PASS, TILE_SOLID, TILE_LOW_COVER | tile_class, tile_set_class - open ground, a wall, or cover that blocks bodies but not projectiles |
| Colors | COLOR_WHITE, COLOR_BLACK, COLOR_RED, COLOR_GREEN, COLOR_BLUE, COLOR_YELLOW, COLOR_CYAN, COLOR_MAGENTA | draw_rect_fill - the eight colors a filled rectangle can be |
| Door modes | DOOR_TWO_WAY, DOOR_ENTER_ONLY, DOOR_EXIT_ONLY | door_set_mode, door_mode - whether a door sends you, receives you, or both |
// Draw GUI event
var hp = 3;
if (btn_pressed(BTN_A)) { hp += 1; }
text_align(ALIGN_CENTER);
draw_rect_fill(14, 145, 20, 10, COLOR_RED);You do not need this to use them, but it explains what you can and cannot do with one.
TILE_PASS is 0, TILE_SOLID is 1, TILE_LOW_COVER is 2, and the three door modes are 0, 1 and 2. You can compare them, and a project can combine a tile type with its own flag bits.PATH_ name with arithmetic.COLOR_ is a fixed set of eight, not any color. It is the palette the rectangle-drawing functions were built around, not a general color type.BTN_ constants name physical buttons. A project can also name its own input actions (jump, fire) in Project Settings and ask about them with action_pressed(jump). Those are your names, not part of this list. See Project settings.GBML has the same idea for your own numbers. #macro NAME value defines a name that is replaced by its value wherever it appears, and enum Name { A, B, C } makes a small set of named whole numbers. Put a #macro in a script and every object can use it. Put one in a single event file and only that file can. The Digger template keeps its CELL, the size of a tile, in one script this way. Expressions and statements covers both.